import { Type } from '@angular/core';
import { RenderItem } from '../render-item';

export class BaseMapTool {
    static current: BaseMapTool = new BaseMapTool();
    renderItemMap: { key: string, component: Type<any> }[] = [];

    getRenderItem(key: string, componentData?: any, dataModel?: any, event?: () => void) {
        const result = this.renderItemMap.find(item => item.key === key);
        if (result) {
            const component = result.component;
            return this.generateRenderItem(component, componentData, dataModel, event);
        } else {
            return null;
        }
    }

    private generateRenderItem(component: Type<any>, componentData?: any, dataModel?: any, event?: () => void) {
        return new RenderItem(component, componentData, dataModel, event);
    }
}
